<template>
    <div>
        <Form :label-width="140" inline>
            <Form-item label="行政区划:">
                <area-linkage :areaCode.sync="queryParam.azaa0001" ></area-linkage>
            </Form-item>
            <Form-item label="区划简称：">
                <Input style="width: 130px" v-model="queryParam.azaa0003" />
            </Form-item>
            <Form-item label="区划全称：">
                <Input style="width: 170px;" v-model="queryParam.azaa0002" />
            </Form-item>
            <Form-item label="区划状态：">
                <Select v-model="queryParam.azaa0106" style="width:100px">
                    <Option value="1">设立</Option>
                    <Option value="0">撤销</Option>
                </Select>
            </Form-item>
            <Form-item label="是否配置组织机构：">
                <Select v-model="queryParam.azaa0114" style="width:100px">
                    <Option value="1">是</Option>
                    <Option value="0">否</Option>
                </Select>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                <Button type="primary" @click="handleAdd()">录入</Button>
                </span>
                <span style="float: right;">
                      <Button type="primary" @click="searchQuery">查询</Button>
                <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                </span>
            </Row>
        </Form>
        <Modal v-model="visible" :title="title" width="800" style="position:relative;">
            <Form ref="formData" :model="formData" :label-width="150" :rules="rules" inline>
                <FormItem label="行政区划名称:" prop="azaa0002">
                    <Input v-model="formData.azaa0002"   placeholder="" v-bind:disabled="disable" ></Input>
                </FormItem>
                <FormItem label="行政区划简称:" prop="azaa0003">
                    <Input v-model="formData.azaa0003"   v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划编码:" prop="azaa0001">
                    <Input v-model="formData.azaa0001"   v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划级别名称:" prop="azaa0004">
                    <Select v-model="formData.azaa0004" placeholder="" style="width: 186px" v-bind:disabled="disable" >
                        <Option value="1">市级</Option>
                        <Option value="2">区县级</Option>
                        <Option value="3">乡镇街道级</Option>
                        <Option value="4">村社区级</Option>
                    </Select>
                </FormItem>
                <FormItem label="长途电话区号:" prop="azaa0005">
                    <Input  v-model="formData.azaa0005"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="邮政编码:" prop="azaa0006">
                    <Input  v-model="formData.azaa0006"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划面积量:" prop="azaa0007">
                    <Input  v-model="formData.azaa0007"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划设立日期:" prop="azaa0008">
                    <Date-picker type="date" v-model="formData.azaa0008" format="yyyy-MM-dd"  v-bind:disabled="disable" style="width: 186px"></Date-picker>
                </FormItem>
                <FormItem label="政府驻地名称:" prop="azaa0010">
                    <Input  v-model="formData.azaa0010"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划全拼:" prop="azaa0103">
                    <Input  v-model="formData.azaa0103"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="行政区划简拼:" prop="azaa0104">
                    <Input  v-model="formData.azaa0104"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="金民区划编码:" prop="azaa0107">
                    <Input  v-model="formData.azaa0107"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="救助证区划编码:" prop="azaa0108">
                    <Input  v-model="formData.azaa0108"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="排序号:" prop="azaa0102">
                    <Input  v-model="formData.azaa0102"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="核对区划系统编码:" prop="azaa0109">
                    <Input  v-model="formData.azaa0109"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
                <FormItem label="组织机构:" prop="azaa0114">
                    <Select v-model="formData.azaa0114" style="width:186px" v-bind:disabled="disable" filterable>
                        <Option value="">请选择</Option>
                        <Option v-for="item in officeList" :value="item.value" :key="item.index">{{ item.label }}</Option>
                    </Select>
                </FormItem>
                <FormItem label="行政区划描述:" prop="azaa0105">
                    <Input  type="textarea" style="width:186px" :autosize="{minRows: 2,maxRows: 5}" v-model="formData.azaa0105"  v-bind:disabled="disable" placeholder="" ></Input>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button @click="visible = false">关闭</Button>
                <Button type="primary" @click="handleSubmit('formData')" v-if="showSubmit">确定</Button>
            </div>
        </Modal>
        <div class="table_div">
            <Table :columns="columns" :data="tableData" :loading="Loading">
                <template slot-scope="{ row, index  }" slot="action">
                    <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(index)">编辑</Button>
                    <Button type="success" size="small" style="margin-right: 5px" @click="handleView(index)">详情</Button>
                    <Button type="error"  v-if="row.azaa0106=='0'" size="small" style="margin-right: 5px" @click="remove(row)">设立</Button>
                    <Button type="error"  v-if="row.azaa0106!='0'" size="small" style="margin-right: 5px" @click="remove(row)">撤销</Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import { postAction } from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import DateFormat from '@/plugins/format.js'
    export default {
        mixins: [CommonMixin],
        components: {
            //dictSelect
        },
        data() {
            return {
                disable: false,
                officeList: [
                ],
                rules: {
                    azaa0002: [
                        { required: true, message: '行政区划名称不能为空', trigger: 'blur' }
                    ],
                    azaa0003: [
                        { required: true, message: '行政区划简称不能为空', trigger: 'blur' }
                    ],
                    azaa0001: [
                        { required: true,  pattern: /^[a-z0-9]+$/,message: '行政区划编码不能为空', trigger: 'change' }
                    ],
                    azaa0004:[
                        { required: true,  message: '行政区划级别名称不能为空', trigger: 'change' }
                    ],
                    azaa0107:[
                        { required: true,  message: '金民区划编码不能为空', trigger: 'change' }
                    ],
                    azaa0109:[
                        { required: true,  message: '核对区划系统编码不能为空', trigger: 'change' }
                    ]
                },
                columns: [
                    {
                        title: '行政区划名称',
                        key: 'azaa0002',
                        align: 'center',
                        // width: '250'
                    },
                    {
                        title: '行政区划编码',
                        key: 'azaa0001',
                        align: 'center',
                        // width: '150'
                    },
                    {
                        title: '行政区划简称',
                        key: 'azaa0003',
                        align: 'center',
                        // width: '130'
                    },
                    // {
                    //     title: '长途电话区号',
                    //     key: 'azaa0005',
                    //     align: 'center',
                    //     width: '100'
                    // },
                    // {
                    //     title: '邮政编码',
                    //     key: 'azaa0006',
                    //     align: 'center',
                    //     width: '100'
                    // },
                    {
                        title: '是否配置组织机构',
                        key: 'azaa0114',
                        align: 'center',
                        render: (h, params) => {
                            if (params.row.azaa0114 == undefined) {
                                return h('span', '否');
                            } else {
                                return h('span', '是');
                            }
                        }
                    }
                    ,
                    {
                        title: '区划状态',
                        key: 'azaa0106',
                        align: 'center',
                        // width: '100',
                        render: (h, params) => {
                            if (params.row.azaa0106 == '0') {
                                return h('span', '撤销');
                            } else {
                                return h('span', '设立');
                            }
                        }
                    }
                    ,{
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        slot: 'action',
                        width: '200',
                        className: 'nopadding',
                    }
                ],
                tableData:[],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss01001Service/pageList",
                    edit: "/api/ac/subsistence/ss01001Service/update",
                    add: "/api/ac/subsistence/ss01001Service/insert"
                },
                formData: {
                    id: '',
                    azaa0001: '',
                    azaa0002: '',
                    azaa0003: '',
                    azaa0004: '',
                    azaa0005: '',
                    azaa0006: '',
                    azaa0007: '',
                    azaa0008: '',
                    azaa0009: '',
                    azaa0010: '',
                    azaa0102: '',
                    azaa0103: '',
                    azaa0104: '',
                    azaa0105: '',
                    azaa0107: '',
                    azaa0108: '',
                    azaa0109: '',
                    azaa0114: '',
                },
                queryParam: {},
                visible:false,
                showSubmit:true,
                dataCount:0,
                pageSize:10,
                modal: false,
                title:""
            }
        },
        methods: {
            initOffice(){
                var that=this;
                var param = {
                };
                postAction('/api/ac/subsistence/ss01001Service/findOfficeList', param).then((res) => {
                    //conso.log("officeService:"+res.data.data);
                    that.officeList = res.data.data.data;
                })
            },
            remove (item) {
                let str = item.azaa0106 =='0' ? '设立' : '撤销';
                let azaa0106 = item.azaa0106 =='0' ? '1' : '0';
                this.$Modal.confirm({
                    title: '确定'+str+'该区划数据吗',
                    onOk: () => {
                        var dataParam = {
                            id: item.id,
                            azaa0106: azaa0106,
                        }
                        postAction('/api/ac/subsistence/ss01001Service/delete', dataParam).then((res) => {
                            this.$Notice.success({ title: '操作成功', desc: '' })
                            this.loadData();
                        }).finally(() => {

                        })
                    }
                })
            },
            handleAdd () {
                let that=this;
                that.title="行政区划录入"
                let record={};
                that.visible = true
                that.showSubmit = true
                that.formData = Object.assign({}, record)
            },
            handleEdit (index) {
                let that=this;
                that.title="行政区划编辑"
                that.disable = false;
                let record=that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.showSubmit = true
                    that.formData = Object.assign({}, record)
                    that.formData.azaa0008 = DateFormat( record.azaa0008, 'YYYY-MM-DD')
                } else {
                    that.visible = false
                }
            },
            handleView (index) {
                let that=this;
                that.title="行政区划查看"
                that.disable = true;
                let record=that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.showSubmit = false
                    that.formData = Object.assign({}, record)
                    that.formData.azaa0008 = DateFormat( record.azaa0008, 'YYYY-MM-DD')
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let that=this;
                        let dataParam = {
                            id: that.formData.id,
                            azaa0001: that.formData.azaa0001,
                            azaa0002: that.formData.azaa0002,
                            azaa0003: that.formData.azaa0003,
                            azaa0004: that.formData.azaa0004,
                            azaa0005: that.formData.azaa0005,
                            azaa0006: that.formData.azaa0006,
                            azaa0007: that.formData.azaa0007,
                            azaa0008: that.formData.azaa0008,
                            azaa0009: that.formData.azaa0009,
                            azaa0010: that.formData.azaa0010,
                            azaa0102: that.formData.azaa0102,
                            azaa0103: that.formData.azaa0103,
                            azaa0104: that.formData.azaa0104,
                            azaa0105: that.formData.azaa0105,
                            azaa0107: that.formData.azaa0107,
                            azaa0108: that.formData.azaa0108,
                            azaa0109: that.formData.azaa0109,
                            azaa0114: that.formData.azaa0114,
                        }
                        let url=null;
                        if(dataParam.id==null){
                            url=that.url.add
                        }else{
                            url=that.url.edit
                        }
                        postAction(url, dataParam).then((res) => {
                            if(res.data.data.errcode==0) {
                                that.visible = false
                                this.$Message.success("提交成功！")
                                this.loadData();
                                this.initOffice;
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    }else {
                        this.$Notice.error({ title: '必填信息未填写完成!', desc: '必填信息未填写完成!' })
                    }
                });
            }
        },
        created() {
            this.loadData();
            this.initOffice();
        },
    }
</script>
<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }
</style>
